define(function () {

    var self;
    var CHARACTERISTICS = [];
    var others = {
        inx: 0
    };
    var zpcxConfirm = app.Module.extend({

        init: function () {
            self = this;
            self.mData = {
                orderSet: {}
            };
            self.searchData = {
                keyword: ''
            }
            self._super({
                _tag: 'p_zpcxconfirm', // key, 对象放进pageModule
                _sliderId: 'slider', // tabs
                _refreshAutoInit: true //自动加载刷新控件
            }, win);

            mui.ready(function () {

                Vue.component('zpcxconfirm-listitem', {
                    template: app.getByid(doc, 'item-template'),
                    props: {
                        model: Array
                    },
                    methods: {
                        update: function (item, d) {
                            var msg = "", msg1;
                            if (d == 'Y') {
                                msg = "确认成功";
                                msg1 = '是否确认订单？';
                            } else if (d == 'N') {
                                msg = "取消成功";
                                msg1 = '是否取消订单？';
                            } else if (d == 'X') {
                                msg = "作废成功";
                                msg1 = '是否作废订单？';
                            }
                            app.ajax({
                                xurl: "api/wx/gwat210/updateData",
                                loading: true,
                                confirm: {
                                    msg: msg1
                                },
                                xdata: {
                                    GWCOACTI: d,
                                    GWCODOCNO: item.GWCODOCNO,
                                    _GWCO007:item.GWCO007,
                                    _GWCO012: item.GWCO012,
                                    _GWCO013: item.GWCO013,
                                    _GWCO026: item.GWCO026,
                                    _GWAKL003: item.GWAKL003
                                },
                                cb: function (result) {
                                    if (result.ok) {
                                        app.alert({
                                            msg: msg,
                                            ok: function () {
                                                self._refresh();
                                            }
                                        });
                                    } else {
                                        app.toast(result.data.message);
                                    }
                                }
                            })
                        }
                    }
                });

                new Vue({
                    el: doc.getElementById('footdiv'),
                    data: others,
                    methods:{
                        update: function (d) {
                            self.update(d);//批量修改状态
                        },
                    }

                });

                setTimeout(function (goods) {
                    $('#allCheck').click(function () { //全选
                        var items = self._getRefreshObj().data;
                        if ($('#allCheck').is(':checked')) {
                            $('#pullRefresh input[type=checkbox]').prop('checked', true);
                            for (var i = 0; i < items.length; i++) {
                                items[i].checked = true;
                            }
                        } else {
                            $('#pullRefresh input[type=checkbox]').prop('checked', false);
                            for (var i = 0; i < items.length; i++) {
                                items[i].checked = false;
                            }
                        }
                    });

                }, 200);
            });
        },
        update: function (d) {

            var items = self._getRefreshObj().data;
            var list = [];
            for (var i = 0; i < items.length; i++) {
                if (items[i].checked == true) {
                    list.push(items[i]);
                }
            }
            var msg1 = "";
            var msg2 = "", msg3;
            if (d == 'Y') {
                msg1 = "请选择需要确认的询单";
                msg2 = "批量确认成功";
                msg3 = "是否批量确认?";
            } else if (d == 'N') {
                msg1 = "请选择需要取消确认的询单";
                msg2 = "批量取消成功";
                msg3 = "是否批量取消?";
            } else if (d == 'X') {
                msg1 = "请选择需要作废的询单";
                msg2 = "批量作废成功";
                msg3 = "是否批量作废?";
            }
            if (list.length == 0) {
                app.toast(msg1);
                return;
            }
            var _data = {
                CHARACTERISTICS: []
            };
            for (var i = 0; i < list.length; i++) {
                _data.CHARACTERISTICS.push({
                    GWCOACTI: d,
                    GWCODOCNO: list[i].GWCODOCNO,
                    _GWCO007:list[i].GWCO007,
                    _GWCO012: list[i].GWCO012,
                    _GWCO013: list[i].GWCO013,
                    _GWCO026: list[i].GWCO026,
                    _GWAKL003: list[i].GWAKL003
                })
            }
            app.ajax({
                xurl: "api/wx/gwat210/update",
                loading: true,
                confirm: {
                    msg: msg3
                },
                xdata: {
                    obj: app.jsonString(_data)
                },
                cb: function (result) {
                    if (result.ok) {
                        app.toast(msg2);
                        for (var i = 0, flag = true; i < items.length; flag ? i++ : i) {
                            if (items[i].checked == true) {
                                items.splice(i, 1);
                                flag = false;
                            } else {
                                flag = true;
                            }
                        }
                    } else {
                        app.toast(result.data.data.message);
                    }
                }
            })
        },
        _search:function(data){
            self.searchData.keyword = data.keyword.trim();
            self._refresh();
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                // self._refreshIds = ['scrollN', 'scrollY','scroll'];
                self._refreshIds = ['scrollN', 'scrollY'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat210/getGwcoDatas",
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    GWAA003: app.cookie('_WX_ACCOUNT_'),//获取微信号
                    GWCOACTI: goods.type.replace('scroll', ''),//注意页面上 不是1 2 3 是 Y N
                    keyword: self.searchData.keyword,//输入的查询条件 ：产品编号、意向客户姓名
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        goods.data.pushArray(data.data.addMap({
                            checked: false
                        }), goods.page == 0);
                        
                        _super({
                            obj: goods,
                            dataLen: data.data.length,
                            nodata: self._refreshIndex == 0 ? '无未确认询单...' : (self._refreshIndex == 1 ? '无已确认询单...' : '无询单...')
                        });
                    }
                }
            });
        },
        _slide: function (i) {// i  就是 _refreshIds的下标
            others.inx = i;
            self._refresh();
        },
        _lazy: function () {
            this._super();

            app.taps.call(win,[
                {
                    o:'btn_N',
                    cb:function () {
                        self.update("N");
                    }
                },
                {
                    o:'btn_Y',
                    cb:function (res) {
                        self.update("Y");
                    }
                },
                {
                    o:'btn_X',
                    cb:function (res) {
                        self.update("X");
                    }
                }
            ]);
        }
    });

    return new zpcxConfirm();

});